<!DOCTYPE html>
<head>
    <title>确认订单页面</title>
    @include('web.layout.head')
    @include('web.layout.header_proscenium')
    <link rel="stylesheet" href="{{mix('/css/web/order/submin_cart.css')}}">
    <link rel="stylesheet" href="{{mix('/css/web/user/address.css')}}">
    <script src="{{mix('/js/web/user/address.js')}}"></script>
</head>

<body>
    <div class="shopcar-header">
        <div class="w1200 f-cb">
            <a class="logo fl" href="<?php echo asset('');?>"><img src="{{asset('/img/web/logo/forget_logo.png')}}" alt=""></a>
            <div class="tit fl">订单页</div>
            <img class="flow fr" src="{{asset('/img/web/order/img115.jpg')}}" alt="" class="fr">
        </div>
    </div>
    <form action="/member/buyer/orders" method="post" accept-charset="utf-8"  id="form-post" name="form-post">
        {{csrf_field()}}
        <div class="submit-order-wrap">
            <div class="w1200">
                <div class="subtitle"> 填写并确认订单信息</div>
                <div class="fir-wrap w-f">
                    <h3>收货地址确认</h3>
                    <div class="address-list f-cb">
                        <ul>
                            @if($address)
                                @foreach($address as $item)
                                    <li data-id="{{$item['id']}}" class="{{$item['is_default'] ? 'hover' : ''}}">
                                        <div class="cont">
                                            <span class="tit f-cb pro">
                                                <span class=" tt"> {{$item['receiver']}}</span>
                                                <span class="word">
                                                {{$item['address']}}        {{$item['phone']}}
                                                </span>
                                            </span>
                                        </div>
                                        <span class="seled"></span>
                                    </li>
                                    <?php
                                        if($item['is_default']){
                                            $address_id = $item['id'];
                                        }
                                    ?>
                                @endforeach
                            @endif
                        </ul>
                        <input type="hidden" name="address_id" value="{{isset($address_id) ? $address_id : ''}}">
                    </div>
                    <div class="addr-mana f-cb">
                        <a href="" class="new-addr-use fl pop-new-addr">添加收货地址</a>
                        <a target="_blank" href="{{asset('/member/address')}}" class="fl" style="color:#fd6631;margin-left:20px;">管理收货地址</a>
                    </div>
                </div>
                <div class="sec-wrap">
                    <h3>确认订单信息</h3>
                    <div class="pro-tab">
                        <table class="type-tit" width="100%">
                            <tr style="background: #eee;">
                                <th width="6%">商家</th>
                                <th width="20%" class="tex-ct">商品信息</th>
                                <th width="11%" class="tex-ct">单价(元)</th>
                                <th width="9%" class="tex-ct">数量</th>
                                <th width="7%">小计(元)</th>
                            </tr>
                        </table>
                        <div class="js-shop-item">
                            @if($shops)
                                @foreach($shops as $shop)
                                <div class="item item{{$shop['sp_id']}}" data-shopid="{{$shop['sp_id']}}">
                                    <div class="clear"></div>
                                    <div class="shopnm"><span class="shopnamedt" data-id="122">{{$shop['sp_name']}}</span></div>
                                    <?php
                                        $freight = 0.00;
                                        $product_money = 0.00;
                                    ?>
                                    @foreach($shop['skus'] as $sku)
                                    <input type="hidden" name="sku_num[{{$sku['id']}}]" value="{{$sku['buy_num']}}">
                                    <table class="proli-tab coupon_table_1" test="test" width="100%">
                                        <tbody>
                                            <tr class="pro-tr" data-id="1">
                                                <td width="6%">
                                                    <a href="/product/info/{{$sku['product']['id']}}/{{$sku['id']}}" class="img" target="_blank">
                                                        <img style="width:80px; height:80px" src="{{$sku['product']['cover_image']}}" alt="">
                                                    </a>
                                                </td>
                                                <td width="20%" valign="top" class="">
                                                    <div class="cont">
                                                        <a href="/product/info/{{$sku['product']['id']}}/{{$sku['id']}}" class="name" target="_blank">{{$sku['product']['name']}}</a>
                                                        <?php
                                                            $attribute_str = '';
                                                            if($sku['attributes']){
                                                                $attributes = json_decode($sku['attributes'], 1);
                                                                if($attributes){
                                                                    foreach($attributes as $attribute){
                                                                        $attribute_str .= ' | ';
                                                                        $attribute_str .= $attribute['attr_name'] . ':' . $attribute['val'];
                                                                    }
                                                                }else{
                                                                    $attributes = explode(";",$sku['attributes']);
                                                                    foreach($attributes as $attribute){
                                                                        $ar = explode(",",$attribute);
                                                                        $str = "";
                                                                        foreach( $ar as $a){
                                                                            $v = explode(":",$a);
                                                                            if(isset($v[1])){
                                                                                $str .= ":".$v[1];
                                                                            }
                                                                        }

                                                                        $str  = substr($str, 1);
                                                                        $attribute_str .= $str." ";
                                                                    }

                                                                }
                                                            }
                                                        ?>
                                                        <span class="font">{{$sku['product']['model']}} {{$attribute_str}}</span>
                                                    </div>
                                                </td>
                                                <td width="11%" class="tex-ct">
                                                    <span class="unit">{{$sku['sale_price']}}</span>
                                                </td>
                                                <td width="9%" class="tex-ct">
                                                    <div class="numbox f-cb">
                                                         ×{{$sku['buy_num']}}
                                                        <input type="hidden" class="shop-id num key_num" value="{{$sku['buy_num']}}">
                                                    </div>
                                                </td>
                                                <td width="7%" class="tex-ct"><span class="sum-pri" shop-id="1">{{sprintf("%.2f",$sku['sale_price'] * $sku['buy_num'])}}</span></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    <?php
                                        $freight += $sku['freight'] * $sku['buy_num'];
                                        $product_money += $sku['sale_price'] * $sku['buy_num'];
                                    ?>
                                    @endforeach
                                    <div class="fpmange invoice_shop_content_{{$shop['sp_id']}}" >
                                        <input type="hidden" class="invoice_shop_{{$shop['sp_id']}}" name="invoices[{{$shop['sp_id']}}]" value="{{$default_invoice ? $default_invoice['id'] : ''}}">
                                        <div class="tit">
                                            发票管理:
                                            <span class="invoice_type">
                                                @if($default_invoice)
                                                    @if($default_invoice['invoice_message'] == 1)
                                                        个人发票
                                                        <?php $default_invoice_type = 'personal_invoice';?>
                                                    @else
                                                        {{$default_invoice['invoice_type'] == 1 ? '普通发票' : '专用发票'}}
                                                        @if($default_invoice['invoice_type'] == 1)
                                                            <?php $default_invoice_type = 'company_regular_invoice';?>
                                                        @else
                                                            <?php $default_invoice_type = 'company_special_invoice';?>
                                                        @endif
                                                    @endif
                                                @else
                                                    不开发票
                                                    <?php $default_invoice_type = 'no_invoicing';?>
                                                @endif
                                            </span>
                                            <span class="edit" data-shop-id="{{$shop['sp_id']}}" table-key=1>修改</span>
                                        </div>
                                        <div class="taitou">{{$default_invoice ? $default_invoice['invoice_title'] : '不开发票'}}</div>
                                        <div class="gl"><a href="{{asset('/member/buyer/invoices')}}"  target="_blank"> 管理发票信息</a></div>
                                        <div class="wx">温馨提示：发票的开票金额仅限实际支付金额（不包含积分抵扣等优惠部分）。每月25日（含25日）之后的付款订单，将在下月开具发票</div>
                                    </div>
                                    <div class="f-cb w-f mt10">
                                        <span class= "cost_goods" hidden>此订单包含需要您承担运费的商品</span>
                                    </div>
                                    <div class="fl remark">
                                        <span class="fl bz">备注：</span>
                                        <input name='remark[{{$shop['sp_id']}}]'  type="text" class="fl tex content" placeholder="补充填写其他信息，如有快递不到也请留言备注" />
                                    </div>
                                    <div class="clear"></div>
                                    <div class="cost">快递运费：<span class="oran f14  freight_money">¥ <i>{{$freight}}</i></span></div>
                                    <div class="fr sum-price"><span class="quota_coupons quota_coupons_title"></span>合计：<span class="oran f14 bold bold{{$shop['sp_id']}}">¥ <i>{{$freight + $product_money}}</i></span></div>
                                    <div  class="cost"><span class= "cost_goods freight_hint"></span></div>
                                </div>
                                @endforeach
                            @endif
                        </div>
                    </div>
                    <div class="clear"></div>
                    <div class="bot-oper f-cb w-f">
                        <a href=" {{asset('/member/buyer/carts')}}" class="fl return-car">返回进货单</a>
                        <a href="javascript:;"><input type="submit" class="fr sub-btn" product-type="1" value="去付款"></a>
                        <span class="fr oran f24">￥ <span class="all-sum" id="all-sum"></span></span>
                        <span class="fr">共有 <i class="piece-num" id="piece-num"></i> 件商品， 总计：</span>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <div class="mask"></div>
    <div class="editinvoce">
        <div class="title">发票信息
            <img  class="close_img" src="{{asset('/img/web/order/img121.png')}}">
        </div>
        <div class="lx">
            <ul>
                <li invoice-message-type='2' class="xz first_invoice" data-target="company_regular_invoice">普通发票</li>
                <li invoice-message-type='3' data-target="company_special_invoice" class="company_special_invoice">增值发票</li>
                <li invoice-message-type='1' data-target="personal_invoice" class="personal_invoice">个人</li>
                <li invoice-message-type='0' data-target="no_invoicing" class="no_invoicing">不开发票</li>
            </ul>
        </div>
        <div class="invoice_select">

        </div>

        <div class="invoice_btn btn">确定</div>
    </div>
    <div class="popshow-new-addr pop-hide">
    <div class="m_myaddress">
        <p class="pop-title clearfix"><span>添加收货地址</span><span class="pop-close">×</span></p>
        <form action="{{url('/member/address/order_store')}}" id="address_info" method="post" class="pop-address">
            {!!  csrf_field() !!}
            <input type="hidden" name="addr_id" value="{{old('area_code')}}" />
            <input type="hidden" name="area_code" value="{{old('area_code')}}" />
            <input type="hidden" name="province_code" value="{{old('province_code')}}" />
            <input type="hidden" name="city_code" value="{{old('city_code')}}" />
            <input type="hidden" id="address_head" name="address_head" value="{{old('address_head')}}" />
            <div class="itembox">
                <div class="item first clearfix">
                    <span class="item-label f-lh36"><i>*</i>所在地区</span>
                    @include('web.layout.city')
                    @if($errors->has('area_code'))
                        <p class="jm_error fl">{{$errors->first('area_code')}}</p>
                    @else
                        <p class="jm_error fl"></p>
                    @endif
                </div>
                <div class="item clearfix">
                    <span class="item-label f-lh36"><i>*</i>详细地址</span>
                    <textarea name="address" class="item-textarea submit_val" autocomplete="off" placeholder="无需重复填写省市区，小于75个字">{{old('address')}}</textarea>
                    @if($errors->has('address'))
                        <p class="jm_error fl">{{$errors->first('address')}}</p>
                    @else
                        <p class="jm_error fl"></p>
                    @endif
                </div>
                <div class="item item-fullname clearfix">
                    <span class="item-label f-lh36"><i>*</i>收货人</span>
                    <input type="text" value="{{old('receiver')}}" name="receiver" class="item-input item-input-fullname submit_val" placeholder="不能为昵称、X先生、X小姐等，请使用真实姓名,小于20字符" autocomplete="off">
                    @if($errors->has('receiver'))
                        <p class="jm_error fl">{{$errors->first('receiver')}}</p>
                    @else
                        <p class="jm_error fl"></p>
                    @endif
                </div>
                <div class="item clearfix">
                    <span class="item-label f-lh36"><i>*</i>手机号码</span>
                    <input type="text" value="{{old('phone')}}" name="phone" class="item-input item-input-mobile submit_val" placeholder="手机号码" autocomplete="off">
                    @if($errors->has('phone'))
                        <p class="jm_error fl">{{$errors->first('phone')}}</p>
                    @else
                        <p class="jm_error fl"></p>
                    @endif
                </div>
                <div class="item clearfix addr-def">
                    <span class="item-label f-lh36">&nbsp</span>
                    <label style="user-select: none">
                         <input type="checkbox" name="is_defult" style="vertical-align:middle;margin-left:5px;">设为默认
                    </label>
                </div>
                <div class="item-bottom clearfix">
                    <input class="item-submit submit_add" type="submit" value="保存新地址"/>
                </div>
            </div>
         </form>
    </div>
</div>
    <script type="text/javascript">
        var invoice_list = '/member/buyer/invoices?type=order_select';
        var current_shop_id = '';
        var current_type = '{{$default_invoice_type}}';
        $(function(){
            $(".edit").click(function(){
                current_shop_id = $(this).data('shop-id');
                $.ajax({
                    url: invoice_list,
                    type: 'get',
                    data:{current_type:current_type},
                    success:function(html){
                        $('.invoice_select').html(html);
                    }
                });
                $(".lx ul li").removeClass('xz');

                if(current_type=='no_invoicing'){
                    $(".no_invoicing").addClass('xz');
                }else{
                    var li = $(".lx ul ."+current_type)[0];
                    $(li).trigger('click');
                }

                if($('.invoice_select .personal_invoice').find('.invoice_data').length < 1){
                    $(".invoice_btn").hide();
                }else{
                    $(".invoice_btn").show();
                }
                setTimeout(function(){
                    $(".editinvoce").show();
                    $(".fpdt").show();
                },200);
             })
            $(".lx ul li").click(function(){
                // 选项卡选择不更改全局发票选择状态。确认按钮更改发票状态。
                _this_current_type = $(this).data('target');
                //选择发票类型
                if($('.' + _this_current_type).find('.invoice_data').length < 1){
                    $(".invoice_btn").hide();
                }else{
                    $(".invoice_btn").show();
                }
                $('.invoice_select .invoices_content_list').hide();
                $('.invoice_select .' + _this_current_type).show();
                //更换高亮
                $(".lx ul li").removeClass('xz');
                $(this).addClass('xz');
            })
            $(".invoice_btn").click(function(){
                // 当前发票类型应该根据 点击了确认之后的类型相同。
                choose = $('.lx ul .xz'); // 选择被选中的 li 即发票信息
                current_type = $(choose).data('target');

                var $invoice_data = $('.' + current_type).find('.invoice_data');
                var invoice_id = $invoice_data.data('invoice-id');
                var invoice_type = $invoice_data.data('type');
                var invoice_title = $invoice_data.data('title');
                $('.invoice_shop_'+current_shop_id).val(invoice_id);
                $('.invoice_shop_content_'+current_shop_id).find('.invoice_type').text(invoice_type);
                $('.invoice_shop_content_'+current_shop_id).find('.taitou').text(invoice_title);
                $(".editinvoce").hide();
            });
            $(".close_img").on('click',function(event) {
                event.preventDefault();
                /* Act on the event */
                $(".editinvoce").hide();
            });
            $(".invoice_manage").on('click',function(event) {
                event.preventDefault();
                /* Act on the event */
                location.href = '/member/inovce_list';
            });
        })
    </script>
    @include('web.layout.footer_ware1')
    <script>
        var new_data = {};
        new_data.information = 'person';
        var product_data = {};
        var library_data ={};
        var shop_data ={};
        new_data.coupons_data = {};
        new_data.invoice_data = {};
        var shops_data =[];
        $(function() {
            $('table .cancel,.add-address .close').click(function(event) {
                $('.add-address').hide();
                $('.mask').hide();
            });
            var bold_sum = 0;
            var piece_num = 0;
            var item_freight_money = 0;

            $('#form-post .item').each(function(i, e) {
                var _this = this;
                var bold_item_sum = 0;
                var product_item_data = [];
                var shop_id = $(this).attr('data-shopid');
                $('#form-post .item'+shop_id+' .sum-pri').each(function(index, el) {
                    bold_item_sum = parseFloat(bold_item_sum) + parseFloat($(this).text());
                    piece_num = parseFloat(piece_num) + parseFloat($(this).parents('tr').find('input.num').val());
                    var sku_id = $(this).parents('tr').find('input.sku_id').val();
                    if(sku_id==0){
                        product_item_data.push({'shop_id':shop_id,'product_id': $(this).parents('tr').find('input.product_id').val(), 'num': $(this).parents('tr').find('input#num').val()});
                        product_item_data[sku_id] = library_data;
                    }else{
                       product_item_data.push({'product_id': $(this).parents('tr').find('input.product_id').val(), 'num': $(this).parents('tr').find('input#num').val()});
                    }

                });
                shops_data.push(product_item_data);
                $('.bold'+shop_id).text((bold_item_sum + parseFloat($('#form-post .item'+shop_id+' .freight_money i').text())).toFixed(2));
                bold_sum = bold_sum + bold_item_sum;
                item_freight_money = parseFloat(item_freight_money) + parseFloat($('#form-post .item'+shop_id+' .freight_money i').text());
            });

            $('#all-sum').text((bold_sum+item_freight_money).toFixed(2));
            //$('#all-sum').text((bold_sum).toFixed(2));
            $("#piece-num").text(piece_num);
            new_data.bold_sum = bold_sum;
        })
    </script>
    <script type="text/javascript">

        $(function() {
            // 发票
            $(".j-bill").click(function() {
                var $this = $(this), type = $this.data('type');
                $this.addClass("hover").siblings().removeClass("hover");
                $this.find(".i").show();
                $this.siblings().find(".i").hide();
                $('input[name="isbill"]').val(type);
                if ('1' == type) {
                    // 发票类型处理
                    var _bill_type = $(".j-bill-type:eq(0)");
                    _bill_type.addClass("hover").siblings().removeClass("hover");
                    _bill_type.find(".i").show();
                    _bill_type.siblings().find(".i").hide();
                    $('input[name="billtype"]').val('1');
                    $this.parents('.invoice-wrap').find('.zengzhi_invoice').show();
                    $this.parents('.invoice-wrap').find('.invoice_taitou').hide();
                    new_data.invoice_type = 1;
                    new_data.information = 'company';
                } else {
                    $this.parents('.invoice-wrap').find('.zengzhi_invoice').hide();
                    $this.parents('.invoice-wrap').find('.invoice_taitou').show();
                    new_data.information = 'person';
                }
            });
            $(".j-bill-type").click(function() {
                var $this = $(this), type = $this.data('type');
                $this.addClass("hover").siblings().removeClass("hover");
                $this.find(".i").show();
                $this.siblings().find(".i").hide();
                $('input[name="billtype"]').val(type);
                new_data.invoice_type = type;
            });
        })
    </script>
    <script type="text/javascript">
        $(function() {
            $("body").on('click', '.address-list ul li', function(event) {
                event.preventDefault();
                /* Act on the event */
                $(this).find(".seled").show();
                $(this).addClass("hover").siblings().removeClass("hover");
                address_id = $(this).attr('data-id');
                $('input[name="address_id"]').val(address_id);
                $(this).siblings().find(".seled").hide();
                _freight();
            });
        })
    </script>
    <script type="text/javascript">
        // 支付
        $(".sub-btn").on('click', function(event) {
            event.preventDefault();

            if(!$('input[name="address_id"]').val()){
                layer.alert('请选择收货地址',{icon: 2});
                return false;
            }
            $('form').submit();
        });

        //添加地址弹框
        var popEle=$('.popshow-new-addr')
        $('.pop-new-addr').on("click",function(e){
            e.preventDefault()
            popEle.removeClass('pop-hide')
            popEle.addClass('pop-show')
        })
        $('.pop-close').on("click",function(){
            popEle.removeClass('pop-show')
            popEle.addClass('pop-hide')
        })
    </script>

</body>

</html>